package com.neuedu.yyzx.common;

import com.neuedu.yyzx.common.convert.DateConverter;
import com.neuedu.yyzx.common.convert.LocalDateConverter;
import com.neuedu.yyzx.common.convert.LocalDateTimeConverter;
import com.neuedu.yyzx.common.util.TokenInterceptor;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author dya
 * Date: 2021/4/27
 * Time: 10:38
 * To change this template use File | Settings | File Templates.
 * Description: TODO
 */
public class BaseConfig implements WebMvcConfigurer {
    @Resource
    LocalDateTimeConverter localDateTimeConverter;
    @Resource
    LocalDateConverter localDateConverter;
    @Resource
    DateConverter dateConverter;
    private TokenInterceptor tokenInterceptor;


    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(localDateTimeConverter);
        registry.addConverter(localDateConverter);
        registry.addConverter(dateConverter);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        List<String> excludePath = new ArrayList<>();
        //排除拦截，除了注册登录(此时还没token)，其他都拦截
//        excludePath.add("/user/register");  //注册
        excludePath.add("/user/login");     //登录
        /*excludePath.add("/static/**");  //静态资源
        excludePath.add("/assets/**");  //静态资源*/

        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
